package com.major.search;

import java.util.ArrayList;

public class RotateArray {
    public static int minNumberInRotateArray(int[] array) {
        if (array.length == 0) {
            return 0;
        }
        int left = 0;
        int right = array.length - 1;
        int mid = (right + left) / 2;
        if (right - left == 0) {
            return array[0];
        }
        // 直到相邻
        while (right - left > 1) {
            // 如果左端小于中间，说明最小值在右半部分
            if (array[0] < array[mid]) {
                left = mid;
            }
            // 如果左端大于中间，在左半部分
            else {
                right = mid;
            }
            mid = (right + left) / 2;
        }
        return array[right];
    }

    public static void main(String[] args) {
        int i = RotateArray.minNumberInRotateArray(new int[]{3, 4, 5, 15,345,567, 2});
        System.out.println(i);
    }
}